package com.ruoyi.api.zero;

import com.ruoyi.redis.RedisService;
import com.ruoyi.system.cache.post.PostCachService;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/api/zeroPost")
@RestController
public class ZeroPostController {
  @Autowired
  private ISysPostService postService;
  @Autowired
  private PostCachService postCachService;
  @Autowired
  private RedisService redisService;
  /**
   * 岗位编码批量生产
   */
  @GetMapping("/updatePostCodeBatch")
  public void updatePostCodeBatch(){
    List<SysPost> sysPosts = postService.selectPostAll();
    for(SysPost post:sysPosts){
      String nextPostCode = postCachService.getNextPostCode(3);
      redisService.incr("lastPostCode",1);
      post.setPostCode(nextPostCode);
      postService.updatePost(post);
    }
  }


}
